Documentation for class post_script

Inherits from 	gadget 

Properties declared in post_script 
	post_script 
	ps_variables 

Class Methods declared in post_script 
	new 
	new_from_file(path) 

Methods declared in post_script 
	any 
		get_post_script_variable(key) 
		post_script 
		ps_variables 
		read_from_file(path) 
		set_post_script(string) 
		set_post_script_variable(key, value) 
		set_ps_variables(dictionary) 
		write_to_file(path) 
	get 
		post_script 
		ps_variables 
	set 
		set_post_script(string) 
		set_ps_variables(dictionary) 

Class 
#begin_class
post_script 
The class post_script is a sub-class of the class gadget. 
The main property of a post-script object is that it may display PostScript code. The property post_script contains the PostScript code as a string.

The property ps_variables is a dictionary where you can store values that can be used by the PostScript code.

Ex:
If the PostScript contains a statement like "x y lineto" you may have x and y stored in ps_variables. You simply send the set_post_script_variable(key, value) message to self.

self:set_post_script_variable(#x, 10)
self:set_post_script_variable(#y, 20)

x y lineto will then be equivalent to 10 20 lineto.
#end_class

Properties 

#begin_property
post_script 
Stores the PostScript code that draws the post_script object. 
#end_property

#begin_property
ps_variables 
Stores a dictionary of post_script variables. These variables can be used by the PostScript code. 
#end_property

Methods 

#begin_method
get_post_script_variable(key) 
Returns the value of the ps_variable identified by the symbol key.
#end_method

#begin_method
post_script 
Returns the post_script property of the post_script object.
#end_method

#begin_method
ps_variables 
Returns the ps_variables property of the post_script object.
#end_method

#begin_method
read_from_file(path) 
Sets the post_script property to the contents of the text file path. The complete path-name is required.
Returns self.
#end_method

#begin_method
set_post_script(string) 
Sets the post_script property to string.
Returns self.
Ex:
Assume that you have a postscript object named my_ps.
s := "0 1 20 {dup dup 20 div 0 1 setrgbcolor 0 moveto 20 lineto stroke} for"
{post_script my_ps}:set_post_script(s)
will draw a 20*20 colored area.
There are two special variables cm_width and cm_hight that can be used in the PostScript code. They will evaluate to the width and the height of the postscript object.
s := "0 1 cm_width {dup dup cm_width div 0 1 setrgbcolor 0 moveto cm_height lineto stroke} for" 
{post_script my_ps}:set_post_script(s)
will draw a colored area that covers the whole postscript object.
#end_method

#begin_method
set_post_script_variable(key, value) 
Sets the value of the ps_variable identified by the symbol key to value.
Returns self.
Ex:
Assume that you have a postscript object named my_ps.
{post_script my_ps}:set_post_script_variable(#my_var, "hello world")
s := "/Times-Roman findfont 18 scalefont setfont 0 30 moveto my_var stringwidth  pop cm_width exch sub 2 div dup cm_height 2 div 5 sub moveto 0 setgray my_var show"
{post_script my_ps}:set_post_script(s)
The postscript object will now display the string contained in my_var in the center of itself.
Now try this:
for x from 1 to 100 do
	{post_script my_ps}:set_post_script_variable(#my_var, x:as_string)
end for
#end_method

#begin_method
set_ps_variables(dictionary) 
Sets the ps_variables property to dictionary.
Returns self.
#end_method

#begin_method
write_to_file(path) 
Writes the post_script property to the file path. If path is not a complete filename the file will be placed in the home directory.
Returns self.
#end_method

Class Methods 

#begin_class_method
new 
Returns a new post_script object.
Ex:
{post_script}:new
#end_class_method

#begin_class_method
new_from_file(path) 
Returns a new post_script object with the post_script property set from the file path.
#end_class_method